package com.myhome.leetcodetest;

import java.util.*;

/**
 * @Author QYiXin
 * @Date 2021 10 19 22 13
 **/
public class Test {
    public static void main(String[] args) {
        String str = "cba";
        char[] chars = str.toCharArray();
        Arrays.sort(chars);
        System.out.println(chars);
    }
    public List<List<String>> groupAnagrams(String[] strs) {
        List<List<String>> result = new ArrayList<>();
        Map<String, List<String>> map = new HashMap<>();
        for (String str : strs) {
            char[] chars = str.toCharArray();
            Arrays.sort(chars);
            System.out.println(chars);
            String str1 = new String(chars);
            List<String> oneMap = map.get(str1);
            if (oneMap == null) {
                oneMap = new ArrayList<>();
                oneMap.add(str);
                map.put(str1, oneMap);
            }else {
                oneMap.add(str);
                map.put(str1, oneMap);
            }
        }
        map.forEach((key,value)->{
            result.add(value);
        });
        return result;
    }
}
